import java.util.ArrayList;
import java.util.Arrays;

public class text3 {
    public static void main(String[] args) {
        String[] k = new String[]{"test","张三","李四","test","test"};
        ArrayList<String> ar =new ArrayList();
        for (int i = 0; i < k.length; i++) {
            ar.add(k[i]);
        }
        for (int i = 0; i < ar.size(); i++) {
            if(ar.get(i).equals("test")){
                System.out.println(ar.remove(i));//输出的同时会执行一遍
                i--;//长度减少1，i必须也少1，否则会跳过下一个数字
            }

        }

        System.out.println(ar);

    }
}
